package com.dog.basics.admin.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.mtkj.CommonDiscountCouponFromDto;
import com.dog.basics.bean.dto.admin.mtkj.DiscountCouponAddDto;
import com.dog.basics.bean.dto.admin.mtkj.DiscountCouponEditDto;
import com.dog.basics.bean.vo.admin.mtkj.CommonDiscountCouponListVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.mtkj.IMtDiscountCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@RestController
@RequestMapping("/admin/discountCoupon")
@Api(value = "优惠券模块", tags = "优惠券模块")
@AllArgsConstructor
public class MtDiscountCouponController {
    private final IMtDiscountCouponService discountCouponService;
    /**
     * 生成通用优惠券
     * @param obj
     * @return
     * @author hangdy
     */
    @SysLog("生成通用优惠券")
    @ApiOperation(value = "生成通用优惠券", notes = "admin:discountCoupon:save")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('admin:discountCoupon:save')")
    public R<Boolean> save(@Valid @RequestBody DiscountCouponAddDto obj) {
        return R.ok(discountCouponService.saveCommonDiscountCoupon(obj));
    }

    /**
     * 修改优惠券
     * @param obj
     * @return
     * @author hangdy
     */
    @SysLog("修改优惠券")
    @ApiOperation(value = "修改优惠券", notes = "admin:discountCoupon:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('admin:discountCoupon:edit')")
    public R<Boolean> edit(@Valid @RequestBody DiscountCouponEditDto obj) {
        return R.ok(discountCouponService.editCommonDiscountCoupon(obj));
    }

    /**
     * 删除优惠券
     * @param id
     * @return
     * @author hangdy
     */
    @SysLog("删除优惠券")
    @ApiOperation(value = "删除优惠券", notes = "admin:discountCoupon:delete")
    @ApiImplicitParam(value = "优惠券Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('admin:discountCoupon:delete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(discountCouponService.deleteDiscountCouponByAdmin(id));
    }

    /**
     * 分页查询优惠券
     * @param: page
     * @param: fromDto
     * @returns
     * @author hangdy
     * @date: 2020/11/14 10:46
     */
    @ApiOperation(value = "查询优惠券", notes = "admin:discountCoupon:getCommonList")
    @GetMapping("/getCommonList")
    @PreAuthorize("@pms.hasPermission('admin:discountCoupon:getCommonList')")
    public R<IPage<CommonDiscountCouponListVo>> findByShopId(PageParam page , CommonDiscountCouponFromDto fromDto){
        return R.ok(discountCouponService.findDiscountCoupon(page,fromDto));
    }
}
